#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //定时器1每隔1000ms   返回值为计时器唯一标识
    id1 = startTimer(1000);
    //定时器2每隔2000ms   返回值为计时器唯一标识
    id2 = startTimer(2000);
}
//重写定时器
void MainWindow:: timerEvent(QTimerEvent *ev){
    //定时器1，每隔一秒+1
    //timerId返回定时器唯一标识
    if(ev->timerId()==id1){
        static int num = 1;
        ui->labelTime->setText(QString::number(num++));
    }
    //定时器2，每隔一秒+1
    //timerId返回定时器唯一标识
    if(ev->timerId()==id2){
        static int num2 = 1;
        ui->labelTime2->setText(QString::number(num2++));
    }
}
MainWindow::~MainWindow()
{
    delete ui;
}

